<?php
/**
 * @notes:
 * @return
 * @author: admin
 * @date: 2024/9/10
 */


namespace addons\shopro\service\lucky;


use app\admin\model\shopro\lucky\Order;

class OrderService
{

    protected $query = null;
    protected $format = null;

    public function __construct(\Closure $format = null, \think\db\Query $query = null)
    {
        $this->query = $query ?: new Order();
        $this->relationSearch = true;
        $this->format = $format;
    }


    public function getList($params,$user)
    {
        if(!$user){
            error_stop('用户不存在！');
        }
        $data=$this->query->with(['server','goods'])->where(['order.user_id'=>$user->id]);


        if($params['type']!=='-1'){
            $data->where(['order.status'=>$params['type']]);
        }
        if($params['lucky_id']){
            $data->where(['lucky_id'=>$params['lucky_id']]);
        }


        $list=$data->order('order.createtime','DESC')->paginate(request()->param('list_rows', 10));

        foreach ($list as $row) {
            $row->visible(['id','order_num','price','createtime','status']);
            $row->visible(['goods']);
            $row->getRelation('goods')->visible(['title','image']);
            $row->visible(['server']);
            $row->getRelation('server')->visible(['open_lucky_time','name']);
        }

        return $list;

    }

}